<?php

namespace app\model;

use think\Model;

class BottomMenu extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'bottom_menu';

    public static function datainitial($mo)
    {
        $weid = weid();

        $datalist = BottomMenu::where(['weid' => $weid, 'module' => $mo])->select()->toArray();

        if (empty($datalist)) {

            $query = BottomMenuOriginal::where(['weid' => '0', 'is_base' => 1, 'module' => $mo]);

            if (config('my.app_name') == config('my.app_v2')) {
                $query->where('is_v2', 1);
            }

            if (config('my.app_name') == config('my.app_v3')) {
                $query->where('is_v3', 1);
            }

            $list = $query->order('sort asc')->select()->toArray();

            if (!empty($list)) {
                foreach ($list as &$vo) {
                    unset($vo['id']);
                    $vo['weid'] = $weid;
                }
                $BottomMenu = new BottomMenu;
                $BottomMenu->saveAll($list);
            }
        }
    }
}
